package com.xc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xc.mapper.BannerMapper;
import com.xc.model.BannerDO;
import com.xc.service.BannerService;
import com.xc.vo.BannerVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xingchen
 * @description
 * @create 2021/11/20 23:15
 */
@Service
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerMapper bannerMapper;

    @Override
    public List<BannerVO> list() {

        List<BannerDO> bannerDOlist = bannerMapper.selectList(new QueryWrapper<BannerDO>().orderByAsc("weight"));

        List<BannerVO> bannerVOList = bannerDOlist.stream().map(m -> {
            BannerVO bannerVO = new BannerVO();
            BeanUtils.copyProperties(m, bannerVO);
            return bannerVO;
        }).collect(Collectors.toList());


        return bannerVOList;
    }
}
